package cn.sylinx.common.ext.web;

import java.io.Writer;

import javax.servlet.Filter;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletResponse;

import cn.sylinx.common.ext.log.GLog;

public abstract class BaseFilter implements Filter {

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {

	}

	@Override
	public void destroy() {

	}

	protected void write(ServletResponse response, Result result) {

		Writer wr = null;
		try {
			response.setCharacterEncoding("UTF-8");
			wr = response.getWriter();
			wr.write(Result.toJson(result));
			wr.flush();
		} catch (Exception e) {
			GLog.error("出现异常:", e);
		} finally {
			try {
				if (wr != null) {
					wr.close();
				}
			} catch (Exception e1) {
			}
		}
	}

}
